<template>
  <BaseMainSlot :show-btn-box="true">
    <!-- 仓管 -->
    <template v-slot:btn-box>
      <ActionBar
        :page-no="24"
        :add-active="true"
        :del-active="delActive"
        :has-cancel="false"
        @add="showDialog"
        @del="del"
      />
    </template>
    <template v-slot:search-box>
      <SearchBox @search="search">
        <div class="seach-box">
          <div class="select-box-content">
            <div class="select-box-content-name">仓库名称：</div>
            <el-input
              v-model="querylist.stordocName"
              placeholder="请输入仓库名称"
              clearable
            />
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">仓库位置：</div>
            <el-input
              v-model="querylist.address"
              placeholder="请输入仓库位置"
              clearable
            />
          </div>
        </div>
      </SearchBox>
    </template>
    <template v-slot:table-box>
      <tdtable
        :page="page"
        :title="title"
        :show-select-column="showSelectColumn"
        :prop-list="propList"
        :table-data="tableData"
        :show-index-column="showIndexColumn"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
        @handleSelectionChange="handleSelectionChange"
      >
        <!-- <template v-slot:headerHandler>
          <el-button type="primary" class="botton" @click="showDialog">添加</el-button>
          <el-button type="primary" class="botton" @click="del">删除</el-button>
        </template>-->
        <template v-slot:handler="{row}">
          <div v-if="row.stordocNo" class="pointer" @click="edit(row)">
            <i class="el-icon-edit"></i>修改
          </div>
        </template>
      </tdtable>
    </template>
    <template v-slot:dialog>
      <AddEditDialog
        :show="show"
        :edit-data="editData"
        @closeDialog="closeDialog"
        @addEvent="addEvent"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";

// import Pagination from "@/components/Pagination";
// import SelectButton from "@/components/equipTypeSelectButton/selcetButton.vue";
import ActionBar from "@/components/ActionBar/index1.vue";
import tdtable from "@/components/table/index.vue";
import AddEditDialog from "./components/add-edit-dialog.vue";
import SearchBox from "@/components/SearchBox/index.vue";
import stordocApi from "@/api/processing-management/stock-manage/warehouse-manage/index";
// import { mymixin } from "@/utils/mixin";
export default {
  name: "ProcessBatchQuery",
  components: {
    // Pagination,
    BaseMainSlot,
    // SelectButton,
    tdtable,
    AddEditDialog,
    SearchBox,
    ActionBar
  },
  // mixins: [mymixin],
  data() {
    return {
      delActive: false,
      show: false,
      querylist: {
        stordocName: "",
        address: ""
      },
      page: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      title: "仓库列表",
      propList: [
        { prop: "stordocName", label: "仓库名称", minWidth: "100" },
        { prop: "address", label: "仓库位置", minWidth: "100" },
        { label: "操作", minWidth: "120", slotName: "handler" }
      ],
      tableData: [],
      // 显示序号
      showIndexColumn: true,
      showSelectColumn: true,
      handle: "add",
      editData: {},
      handleSelectList: []
    };
  },
  computed: {},
  watch: {},
  mounted() {
    this.queryPageList();
  },
  methods: {
    search() {
      this.queryPageList();
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.queryPageList();
    },

    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.queryPageList();
    },
    // 选中table行点击事件
    handleSelectionChange(val) {
      console.log(val);
      this.handleSelectList = [];
      val.forEach(e => {
        this.handleSelectList.push(e.stordocNo);
      });
      if (this.handleSelectList.length > 0) {
        this.delActive = true;
      } else {
        this.delActive = false;
      }
    },
    queryPageList() {
      // 获取数据
      let param = {
        page: this.page.currentPage,
        size: this.page.pageSize,
        entity: this.querylist
      };
      stordocApi.queryPageList(param).then(res => {
        if (res.code === 1) {
          let data = res.data;
          this.page.total = data.totalElements;
          this.tableData = data.content;
        }
      });
    },
    // 添加物料
    addEvent(formData) {
      let params = formData;
      if (this.handle === "add") {
        stordocApi.add(params).then(res => {
          console.log(res);
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.queryPageList();
          }
        });
      }
      if (this.handle === "edit") {
        stordocApi.edit(params).then(res => {
          console.log(res);
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.queryPageList();
          }
        });
      }
    },
    // 删除供应商
    del() {
      if (this.handleSelectList.length < 1) {
        this.$message.error("请选择要删除的数据");
        return;
      }
      let params = {
        noList: this.handleSelectList
      };
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass"
      })
        .then(() => {
          stordocApi.del(params).then(res => {
            if (res.code === 1) {
              this.$message.success(res.msg);
              this.queryPageList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    edit(row) {
      this.show = true;
      this.handle = "edit";
      this.editData = row;
    },
    // 显示添加弹出框
    showDialog() {
      this.handle = "add";
      this.editData = {};
      this.show = true;
    },
    closeDialog() {
      this.show = false;
      this.editData = {};
    }
  }
};
</script>

<style scoped lang="scss">
@import "~@/styles/variables.scss";

::v-deep .el-collapse-item__header {
  height: 0px;
}
::v-deep .el-collapse-item__content {
  padding-bottom: 10px;
}
::v-deep .el-pagination {
  position: absolute;
  right: 0px;
  bottom: -18px;
}

::v-deep .el-form-item__label {
  min-width: 120px !important;
  text-align: end;
}
.total {
  position: absolute;
  top: 25px;
  left: 300px;
}

::v-deep .el-form-item.is-error {
  .el-input__inner {
    border-color: #f56c6c !important;
  }
}
.botton {
  background-color: #0091b7;
}
.pointer {
  cursor: pointer;
  text-decoration: underline;
}
</style>
